// pages/my-collect-work/my-collect-work.js
import {
  HTTP
} from '../../utils/http'
let http = new HTTP()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    workList: [],
    workPageNum: 1,
    workPageSize: 10,
    workTotal: 0
  },

  onTap(e){
    wx.navigateTo({
      url: '/pages/work-detail/work-detail?id='+e.currentTarget.dataset.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const accountId = options.accountId;
    this.setData({
      accountId: accountId
    })
  },
  getWorkList() {
    http.request({
      url: '/ai/draw/picture/get/account/page',
      method: 'post',
      data: {
        "accountId": this.data.accountId,
        "type": 1,
        "pageNum": this.data.workPageNum,
        "pageSize": this.data.workPageSize
      },
      success: (res) => {
        if (res.code === "0") {
          let list = res.data.list
          var arr1 = this.data.workList;
          var arr2 = list;
          arr1 = arr1.concat(arr2);
          this.setData({
            workList: arr1,
            workTotal: res.data.total
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getWorkList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.setData({
      workList: [],
      workPageNum: 1,
      workPageSize: 10
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (!(this.data.workList && this.data.workList.length > 0)) return
    let currentTotal = this.data.workList.length;
    if (currentTotal <= this.data.workTotal) {
      var current = this.data.workPageNum * 1 + 1;
      this.setData({
        workPageNum: current
      })
      this.getWorkList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})